<?php
namespace Model;
use Think\Model;
    class AuthModel extends Model {
        
        protected $_validate = array(
            //不为空验证
            array('auth_name','require','权限名称不能为空'),
            
            //长度验证
            array('auth_name','1,20','权限名称长度在1~20',0,'length'),
            array('auth_c','1,32','控制器长度在1~32',2,'length'),
            array('auth_a','1,32','操作方法长度在1~32',2,'length'),
        );
        
        
        function tianjia($data){
            //计算权限级别
            if($data['auth_pid']==0){
                $data['auth_level'] = 0;
            }else{
                //获得父级权限等级
                $fauth = $this -> find($data['auth_pid']);
                $flevel = $fauth['auth_level'];
                $data['auth_level'] = $flevel+1;                               
            }
            //添加
            $bool = $this -> add($data);
            
            return $bool;           
        }
    
}